package com.android.binderserverclient0.workmanager

import android.content.Context
import androidx.work.Data
import androidx.work.Worker
import androidx.work.WorkerParameters

class CheckDiskProgressWorker(context: Context, workerParameters: WorkerParameters) :
    Worker(context, workerParameters) {

    override fun doWork(): Result {
        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 10)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 20)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 50)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 70)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 85)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 90)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 95)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 96)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 97)
        }.build())

        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 98)
        }.build())

        //最后一个不会执行
        Thread.sleep(1000)
        setProgressAsync(Data.Builder().apply {
            putInt("progress", 100)
        }.build())

        return Result.success(Data.Builder().apply {
            putInt("progress", 100)
            putInt("code", 200)
            putString("result","mission success")
        }.build())
    }

}